(function(vc) {
    vc.extends({
        data: {
            addProductCategoryInfo: {
                categoryId: '',
                parentCategoryId: '',
                categoryName: '',
                cateTypes: [],
                cateType: '',
                seq: 1,
                isShows: [],
                isShow: '',
                categoryLevel: '1',
                shopId: ''
            }
        },
        _initMethod: function() {
            vc.getDict('product_category', "is_show", function(_data) {
                $that.addProductCategoryInfo.isShows = _data;
            });
            vc.getDict('product_category', "cate_type", function(_data) {
                $that.addProductCategoryInfo.cateTypes = _data;
            });
        },
        _initEvent: function() {
            vc.on('addProductCategory', 'openAddProductCategoryModal', function() {
                $('#addProductCategoryModel').modal('show');
				$that.addProductCategoryInfo.cateType = 1;
				$that.addProductCategoryInfo.isShow = "Y";
            });
        },
        methods: {
            addProductCategoryValidate() {
                return vc.validate.validate({
                    addProductCategoryInfo: $that.addProductCategoryInfo
                }, {
                    'addProductCategoryInfo.categoryName': [{
                            limit: "required",
                            param: "",
                            errInfo: "分类名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "100",
                            errInfo: "分类名称不能超过100位"
                        },
                    ],
                    'addProductCategoryInfo.seq': [{
                            limit: "required",
                            param: "",
                            errInfo: "显示序号不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "显示序号不是有效数字"
                        },
                    ],
                    'addProductCategoryInfo.isShow': [{
                            limit: "required",
                            param: "",
                            errInfo: "是否显示不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "2",
                            errInfo: "是否显示格式错误"
                        },
                    ],
                    'addProductCategoryInfo.cateType': [{
                            limit: "required",
                            param: "",
                            errInfo: "分组目录不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "2",
                            errInfo: "分组目录格式错误"
                        },
                    ],
                });
            },
            saveProductCategoryInfo: function() {
                if (!$that.addProductCategoryValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addProductCategoryInfo.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/productCategory.saveProductCategory',
                    JSON.stringify($that.addProductCategoryInfo), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addProductCategoryModel').modal('hide');
                            $that.clearAddProductCategoryInfo();
                            vc.emit('productCategoryManage', 'listProductCategory', {});
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddProductCategoryInfo: function() {
                let _cateTypes = $that.addProductCategoryInfo.cateTypes;
                let _isShows = $that.addProductCategoryInfo.isShows;
                $that.addProductCategoryInfo = {
                    categoryId: '',
                    parentCategoryId: '',
                    categoryName: '',
                    cateTypes: _cateTypes,
                    isShows: _isShows,
                    cateType: '',
                    seq: 1,
                    isShow: '',
                    categoryLevel: '1',
                    shopId: vc.getCurrentCommunity().shopId
                };
            }
        }
    });
})(window.vc);